package com.pay.game.central.bot;

import org.springframework.stereotype.Component;
import org.telegram.telegrambots.ApiContextInitializer;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

@Component
public class MyBot  {
    private TelegramLongPollingBot mBot;

    private class MyPollBot extends TelegramLongPollingBot{

        @Override
        public void onUpdateReceived(Update update) {
            // TODO 处理接收的信息
        }

        @Override
        public String getBotUsername() {
            return "ListBill";
        }

        @Override
        public String getBotToken() {
            return "1306600915:AAFR-4htjEt1SE_B1-C_sw4K_mDubLVyQnE";
        }

    }
    public MyBot(){
        ApiContextInitializer.init(); // step 1
        mBot = new MyPollBot(); // step 2
        TelegramBotsApi botsApi = new TelegramBotsApi();
        try {
            botsApi.registerBot(mBot);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }

    public void sendMsg(String chatId, String msg){
        SendMessage snd = new SendMessage();
        snd.setChatId(chatId);
        snd.setText(msg);
        try {
            mBot.execute(snd);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }

    }

}
